package com.dingnate.demo.mvc.action;

import com.dingnate.demo.service.INamedService;
import com.dingnate.demo.service.IService;
import com.dingnate.framework.springmvn.GPModelAndView;
import com.dingnate.framework.springmvn.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

@GPController
@GPRequestMapping("/web")
public class FirstAction {
    @GPAutowrited
    private IService service;
    @GPAutowrited("myName")
    private INamedService namedService;

    @GPRequestMapping(value = "/query.json")
    @GPResponseBody
    public GPModelAndView query(HttpServletRequest req, HttpServletResponse resp,
                                @GPRequestParam("name") String name,
                                @GPRequestParam("addr") String addr
                                ) {
        String msg = "name=" + name;
        System.out.println(msg);
        HashMap<String, Object> model = new HashMap<>();
        model.put("name", name);
        model.put("addr", addr);
        return new GPModelAndView("first.gpml", model);
    }

    @GPRequestMapping(value = "/query/.*.json", isRegex = true)
    @GPResponseBody
    public String queryRegex(HttpServletRequest req, HttpServletResponse resp, @GPRequestParam("name") String name) {
        String msg = "name=" + name;
        System.out.println(msg);
        return msg;
    }
}
